package com.tem.system.service.impl;

import com.api.manage.pojo.system.SystemLevelBranchBean;
import com.api.manage.pojo.system.SystemLevelBranchResources;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tem.system.entity.SystemLevelBranch;
import com.tem.system.mapper.SystemLevelBranchMapper;
import com.tem.system.service.ISystemLevelBranchService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 一个分店 只能有一种系统 服务实现类
 * </p>
 *
 * @author 腾木
 * @since 2023-11-17
 */
@Service
public class SystemLevelBranchServiceImpl extends ServiceImpl<SystemLevelBranchMapper, SystemLevelBranch> implements ISystemLevelBranchService {
    public List<SystemLevelBranchBean> getSystemLevelBranchBean(Long sysBranchOfficeId){
        List<SystemLevelBranch> slbs = this.getSystemLevelBranch(sysBranchOfficeId);if(slbs==null||slbs.size()<1)return null;
        List<SystemLevelBranchBean> beans = new ArrayList<>();SystemLevelBranchBean sbean=null;
        for(SystemLevelBranch b:slbs){
            sbean=new SystemLevelBranchBean();
            BeanUtils.copyProperties(b,sbean);
            beans.add(sbean);
        }
        return beans;
    }
    public List<SystemLevelBranchResources> getSystemLevelBranchResources(Long sysBranchOfficeId){
        List<SystemLevelBranch> slbs = this.getSystemLevelBranch(sysBranchOfficeId);if(slbs==null||slbs.size()<1)return null;
        List<SystemLevelBranchResources> beans = new ArrayList<>();SystemLevelBranchResources sbean=null;
        for(SystemLevelBranch b:slbs){
            sbean=new SystemLevelBranchResources();
            BeanUtils.copyProperties(b,sbean);
            beans.add(sbean);
        }
        return beans;
    }

    public List<SystemLevelBranch> getSystemLevelBranch(Long sysBranchOfficeId){
        QueryWrapper<SystemLevelBranch> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(SystemLevelBranch::getSysBranchOfficeId,sysBranchOfficeId);
        return this.list(queryWrapper);
    }
}
